package com.tianfeng.news.ui.dialog;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.tianfeng.news.R;
import com.tianfeng.news.ui.activity.other.HomeUserWithActivity;

/**
 * Data:  2019/6/21
 * Auther: xcd
 * Description:
 */
public class HomeUserWithDialogFragment extends DialogFragment implements View.OnClickListener {

    private boolean isFristWith = true;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_user_with, container);
        view.findViewById(R.id.iv_close).setOnClickListener(this);
        view.findViewById(R.id.iv_getuserwith).setOnClickListener(this);
        getDialog().setCancelable(false);
        getDialog().setCanceledOnTouchOutside(false);
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.5f;
        windowParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(windowParams);
//        Dialog dialog = getDialog();
//        if (dialog != null) {
//            DisplayMetrics dm = new DisplayMetrics();
//            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
//            window.setLayout((int) (dm.widthPixels * 0.7), (int) (dm.widthPixels * 0.75*(1295/1080)));
//        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_getuserwith:
                startActivity(new Intent(getActivity(), HomeUserWithActivity.class));
                break;
            case R.id.iv_close:
                if (userWithDismiss != null){
                    userWithDismiss.onClickDismiss();
                }
                dismiss();

                break;
        }

    }

    UserWithDismiss userWithDismiss;
    public void setUserWithDismiss(UserWithDismiss userWithDismiss){
        this.userWithDismiss = userWithDismiss;
    }
    public interface UserWithDismiss{
        public void onClickDismiss();
    }
}
